from cStringIO import StringIO

output = None

def start():
    global output
    
    output = StringIO()
    
def getvalue():
    global output
    
    if output:
        output.flush()
        return output.getvalue()
    return ""
    
def close():
    global output
    
    try:
        return getvalue()
    finally:
        output = None

def emit(data):
    global output
    
    if output:
        output.write(data + "\n")

